//
//  FeedBackViewController.m
//  didacar
//
//  Created by Yang Yuexia on 15/12/10.
//  Copyright © 2015年 dzmmac. All rights reserved.
//

#import "FeedBackViewController.h"
#import "UIButton+Dzm.h"
#import "SortView.h"

@interface FeedBackViewController ()<UITextViewDelegate,SortSelectedDelegate>
@property (strong, nonatomic) SortView *sortView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgView_layout_top;

@property (weak, nonatomic) IBOutlet UIView *centerView;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *placeHolderLabel;

@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UIButton *commitButton;
- (IBAction)commitAction:(id)sender;

@property (weak, nonatomic) IBOutlet UITextField *textField;



@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"投诉建议";
    [self setLeftBtnItem];
    self.textView.delegate = self;
   
    self.centerView.layer.borderColor = GLOBLE_GRAY_COLOR_1.CGColor;
    self.centerView.layer.borderWidth = 0.45;
    self.centerView.layer.cornerRadius = 4;
    self.centerView.layer.masksToBounds= YES;
    [self.commitButton styleButton];

    
    self.textField.layer.borderColor = GLOBLE_GRAY_COLOR_1.CGColor;
    self.textField.layer.borderWidth = 0.45;
    self.textField.layer.cornerRadius = 4;
    self.textField.layer.masksToBounds= YES;
    self.textField.leftView = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 10, 10)];
    self.textField.leftViewMode = UITextFieldViewModeAlways;
    [self.textField setValue:GLOBLE_GRAY_COLOR_2 forKeyPath:@"_placeholderLabel.textColor"];
    
    // 排序样式
    self.sortView = [[SortView alloc ] init];
    self.sortView.dataList = @[@"线路优化",@"功能、操作",@"司机服务",@"车辆配置",@"订单、费用",@"其他"];
    self.sortView.delegate = self;
    self.sortView.sortType = 1;
}


// 排序点击
-(void)sortSelectedIndex:(NSInteger)index{
    self.textField.text = self.sortView.dataList[index];
}


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    [self.sortView show];
    return NO;
}

#pragma mark ---- UITextViewDelegate ----

- (void)textViewDidChange:(UITextView *)textView{
    if (textView.text.length == 0) {
        self.placeHolderLabel.text = @"请留下您的宝贵意见";
    }else{
        self.placeHolderLabel.text = @"";
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSString *temp = [textView.text stringByReplacingCharactersInRange:range withString:text];
    if (temp.length > 100) {
        textView.text = [temp substringToIndex:100];
        self.placeHolderLabel.text = @"";
        return NO;
    }
    return YES;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.textView resignFirstResponder];
}

//提交
- (IBAction)commitAction:(id)sender
{
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
